import type { BasePageList } from '@/types/base'
import type { UserListParams, User } from './types'
import { BASE_URL } from '@/utils/constants'
import { request } from '@/utils/request'

const UserAPI = {
  getUserList(params: UserListParams = { page: 1, pageSize: 10 }): Promise<BasePageList<User>> {
    return request.get(`${BASE_URL}/user`, { params })
  },
  createUser(data: Omit<User, 'id'>): Promise<User> {
    return request.post(`${BASE_URL}/user`, data)
  },
  getUserDetail(id: number): Promise<User> {
    return request.get(`${BASE_URL}/user/${id}`)
  },
  updateUser(id: number, data: Partial<User>): Promise<User> {
    return request.put(`${BASE_URL}/user/${id}`, data)
  },
  deleteUser(id: number): Promise<void> {
    return request.delete(`${BASE_URL}/user/${id}`)
  },
  batchDeleteUser(ids: number[]): Promise<void> {
    return request.delete(`${BASE_URL}/user`, { data: { ids } })
  }
}

export default UserAPI
